def generate_yh(m):
    result=0
    sanjiao=[]
    for i in range(m+1):
        row=[]
        if i==0:
            row.append(1)
            sanjiao.append(row)
        elif i==1:
            row.append(1)
            row.append(1)
            sanjiao.append(row)
        else:
            for j in range(i+1):
                if j==0 or j==i:
                    row.append(1)
                else:
                    row.append(sanjiao[i-1][j-1]+sanjiao[i-1][j])
            sanjiao.append(row)
    for i in range(m+1):
        for j in range(i+1):
            print sanjiao[i][j],
        print '\n'


generate_yh(5)